package cn.eeepay.boss.action.tradeWarning;

import cn.eeepay.boss.system.DataSource;
import cn.eeepay.boss.system.SystemLog;
import cn.eeepay.framework.service.tradeWarning.TradeWarningService;
import cn.eeepay.framework.util.Constants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping(value = "/tradeWarning")
public class TradeWarningAction {
    private static final Logger log = LoggerFactory.getLogger(TradeWarningAction.class);

    @Resource
    private TradeWarningService tradeWarningService;

    /**
     * 获取交易预警详情
     */
    @RequestMapping(value = "/getTradeWarningInfo")
    @ResponseBody
    @DataSource(Constants.DATA_SOURCE_SLAVE)
    public Map<String,Object> getTradeWarningInfo(@RequestParam("warningCode") String warningCode){
        Map<String, Object> msg=new HashMap<String,Object>();
        try{
            tradeWarningService.getTradeWarningInfo(warningCode,msg);
        } catch (Exception e){
            log.error("获取交易预警详情异常!",e);
            msg.put("status", false);
            msg.put("msg", "获取交易预警详情异常!");
        }
        return msg;
    }

    /**
     * 保存-交易预警
     */
    @RequestMapping(value = "/saveTradeWarningInfo")
    @ResponseBody
    @SystemLog(description = "交易查询-交易预警",operCode="tradeWarning.saveTradeWarningInfo")
    public Map<String,Object> saveTradeWarningInfo(@RequestParam("param") String param){
        Map<String, Object> msg=new HashMap<String,Object>();
        try{
            tradeWarningService.saveTradeWarningInfo("TRADE_ERROR",param,msg);
        } catch (Exception e){
            log.error("保存交易预警异常!",e);
            msg.put("status", false);
            msg.put("msg", "保存交易预警异常!");
        }
        return msg;
    }

    /**
     * 保险-保存-交易预警
     * 权限分开
     */
    @RequestMapping(value = "/saveTradeWarningInfoSafe")
    @ResponseBody
    @SystemLog(description = "保险订单查询-交易预警",operCode="tradeWarning.saveTradeWarningInfoSafe")
    public Map<String,Object> saveTradeWarningInfoSafe(@RequestParam("param") String param){
        Map<String, Object> msg=new HashMap<String,Object>();
        try{
            tradeWarningService.saveTradeWarningInfo("ZJX_ERROR",param,msg);
        } catch (Exception e){
            log.error("保存交易预警异常!",e);
            msg.put("status", false);
            msg.put("msg", "保存交易预警异常!");
        }
        return msg;
    }
}
